/*
 * @Author: 码农 2646995216@qq.com
 * @Date: 2025-02-19 16:45:54
 * @LastEditors: 码农 2646995216@qq.com
 * @LastEditTime: 2025-02-19 20:46:27
 * @FilePath: /pipe/PipeServe.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"comm.hpp"

int main()
{
    Fifo fifo("./mypipe");
    int rfd=open("./mypipe",O_RDONLY);//以只读的方式打开
    if(rfd<0)
    {
        cout<<"read open flase,error:"<<errno<<",eerrstring:"<<strerror(errno)<<endl;
        return 0;
    }

    char buffer[1024]; 

    while(true)
    {
        ssize_t n=read(rfd,buffer,sizeof(buffer)-1);
        if(n>0)
        {
            buffer[n]='\0';
            cout<<"Client say:"<<buffer<<endl;
        }
        else if(n==0)
        {
            cout << "client quit, me too!!" << endl;
            break;
        }
        else{
            cout << "read failed, errno: " << errno << ", errstring: " << strerror(errno) << endl;
            break;
        }
    }

    close(rfd);
    return 0;
}